<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#import "/layout/select.ftl" as my>
<#assign css>
<#--此ftl中用到的css-->
<link rel="stylesheet" href="/assets/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.css">

</#assign>
<#assign js>
<#--此ftl中用到的js-->
<script src="/assets/vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="/assets/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js" charset="UTF-8"></script>
<script>
	$(".btn-submit").click(function () {
		// 校验表单合法
		var bootstrapValidator = $(".form-edit").data('bootstrapValidator');
		bootstrapValidator.validate();
		if(bootstrapValidator.isValid()){
			$.ajax({
				type: "POST",
				url: "/couponInfo/edit",
				data: $(".form-edit").serialize(),
				dataType: "JSON",
				success: function(res){
				    if(res.code=='0'){

                        layer.msg(res.message, {time: 2000
                        }, function(){
                            location.href="/couponInfo/index";
                        });
					}else {
                        layer.msg(res.message);
					}

				}
			});
		}else{
			return false;
		}
	});

    $("#useScope").change(function (e){
        var useScope = e.currentTarget.value;

        var childType = $("#useScopeChildType");
        $.ajax({
            type: "GET",
            url: "/agentService/getChildType/"+useScope,
            dataType: "JSON",
            success: function(res){

                $("#useScopeChildType option").remove();
                $("#useScopeChildType").append("<option value=''>请选择</option>");
                for(var key in res.data){
                    $("#useScopeChildType").append("<option value='"+key+"'>"+res.data[key]+"</option>");
				}

            }
        });



	});

	$('.form-edit').bootstrapValidator({
		message: '请输入有效值',
		feedbackIcons: {
			valid: 'glyphicon glyphicon-ok',
			invalid: 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		}
	});

    $('#useStartTime,#useEndTime').datepicker({
        autoclose: true,
        format:"yyyy-mm-dd",
        todayHighlight:true,
        language:"zh-CN"
    });

    $('#useStartTime').unbind("change");
    $('#useStartTime').change(function(){
        $('#useEndTime').datepicker('setStartDate', $("#useStartTime").val());
    });
    $('#useEndTime').unbind("change");
    $('#useEndTime').change(function(){
        $('#useStartTime').datepicker('setEndDate', $("#useEndTime").val());
    });


</script>
</#assign>
<@layout title="编辑" active="couponInfo">
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>
		<#if isAdd>
            新增
        <#else>
            编辑
        </#if>
		<small>优惠券详细信息</small>
	</h1>
	<ol class="breadcrumb">
		<li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
		<li><a href="#"><i class="fa fa-list-ul"></i> 优惠券管理</a></li>
		<li class="active"><i class="fa fa-edit"></i>
		    <#if isAdd>
                新增
            <#else>
                编辑
            </#if>
		</li>
	</ol>
</section>
<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<!-- Default box -->
			<div class="box  box-primary">
				<form class="form-horizontal form-edit" method="post" action="couponInfo/edit">
					<div class="box-body">
						<input type="hidden" id="id" name="id" value="${couponInfo.id!}">
						<input type="hidden" id="isAdd" name="isAdd" value="${isAdd?string('true','false')}">
						<div class="form-group">
							<label class="col-sm-2 control-label">优惠券名称：</label>
							<div class="col-sm-10">
								<input required placeholder="请输入优惠券名称" id="name" name="name" class="form-control" type="text" value="${couponInfo.name!}" >
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">优惠券类型：</label>
                            <div class="col-sm-10">
							    <@my.select id="type" datas=getDict('COUPON_TYPE')  value="${couponInfo.type!}" defaultValue="请选择"/>
                            </div>
						</div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">有效开始时间：</label>
                            <div class="col-sm-10">
                                <input required placeholder="请输入有效开始时间" id="useStartTime" name="useStartTime" class="form-control" type="text" value="${(couponInfo.useStartTime?string('yyyy-MM-dd'))!}" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">使用截止日期：</label>
                            <div class="col-sm-10">
                                <input required placeholder="请输入使用截止日期" id="useEndTime" name="useEndTime" class="form-control" type="text" value="${(couponInfo.useEndTime?string('yyyy-MM-dd'))!}" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">优惠金额：</label>
                            <div class="col-sm-10">
                                <input required placeholder="请输入优惠金额" id="amount" name="amount" class="form-control" type="text" value="${couponInfo.amount!}" >
                            </div>
                        </div>
						<div class="form-group">
							<label class="col-sm-2 control-label">最低使用金额：</label>
							<div class="col-sm-10">
								<input required placeholder="请输入最低使用金额" id="minGoodsAmount" name="minGoodsAmount" class="form-control" type="text" value="${couponInfo.minGoodsAmount!}" >
							</div>
						</div>

						<#--<div class="form-group">
							<label class="col-sm-2 control-label">优惠券状态：</label>
							<div class="col-sm-10">
								<input required placeholder="请输入优惠券状态" id="state" name="state" class="form-control" type="text" value="${couponInfo.state!}" >
							</div>
						</div>-->
						<div class="form-group">
							<label class="col-sm-2 control-label">使用范围：</label>
							<div class="col-sm-5">
								<@my.select id="useScope" datas=getDict('SERVICE_CLASS')  value="${couponInfo.useScope!}" defaultValue="请选择" />


							</div>
							<div class="col-sm-5">

								<@my.select id="useScopeChildType" datas=getDict('SERVICE_CLASS','${couponInfo.useScope!}')  value="${couponInfo.useScopeChildType!}" defaultValue="请选择"/>

							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">描述：</label>
							<div class="col-sm-10">
								<input required placeholder="请输入描述" id="descs" name="descs" class="form-control" type="text" value="${couponInfo.descs!}" >
							</div>
						</div>


					<div class="box-footer">
						<button type="button" class="btn btn-default btn-back">返回</button>
						<button type="button" class="btn btn-info pull-right btn-submit">提交</button>
					</div>

				</form>
			</div>
			<!-- /.box -->
		</div>
	</div>
</section>
<!-- /.content -->
</@layout>
